package com.ehotting.edsta.circuitDesign.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.ehotting.edsta.circuitDesign.bean.DriveMatchBean;
import com.ehotting.edsta.circuitDesign.bean.PinsBean;

import java.util.*;
import java.util.stream.Collectors;

public class DrivenData {

    private static List<DriveMatchBean> insideMatch(List<PinsBean> mcuNet){

        HashMap<String, List<PinsBean>> modelMap = new HashMap<>();
        for( PinsBean p : mcuNet){
            if(!p.isOccupied()){
                continue;
            }
            if(modelMap.get(p.getModel()) == null){
                modelMap.put(p.getModel(), new ArrayList<>());
            }
            modelMap.get(p.getModel()).add(p);
        }


        List<DriveMatchBean> insideMatchData = new ArrayList<>();
        for(String key : modelMap.keySet()){
            List<PinsBean> pinsBeanList = modelMap.get(key);
            Map<String, String> groupMap = pinsBeanList.stream().collect(
                    Collectors.toMap(PinsBean::getPin, PinsBean::getProperty)
            );
            PinsBean p = pinsBeanList.get(0);
            DriveMatchBean driveMatchBean = new DriveMatchBean();
            driveMatchBean.setSenseModel(p.getModel());
            driveMatchBean.setSenseType(p.getType());
            driveMatchBean.setMcuProperty(p.getProperty());
            driveMatchBean.setGroupData(groupMap);
            insideMatchData.add(driveMatchBean);
        }
        return insideMatchData;
    }


    private static List<DriveMatchBean> outsideMatch(List<List<PinsBean>>replaceNets,
                                                     List<List<List<String>>> replaceNetsReturn,
                                                     List<String> sense_models, boolean[] download){
        //进行网表匹配(返回结果为网表替换数据)，匹配同时提取数据
        String jsonString = JSONObject.toJSONString(replaceNets);
//        List<List<PinsBean>> newReplaceNets = (List<List<PinsBean>>)JSONObject.parseObject(jsonString);
        List<List<PinsBean>> newReplaceNets = JSON.parseObject(jsonString, new TypeReference<List<List<PinsBean>>>(){});
//        return netsMatching(newReplaceNets, replaceNetsReturn, sense_models,download);
        return null;
    }
}
